<template>
  <div>
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="orderBy" label="排序" width="50">
      </el-table-column>
      <el-table-column prop="name" label="分类名称" show-overflow-tooltip>
        <template slot-scope="{ row }">
          <span class="cup" @click="handleEdit(row)">{{ row.name }}</span>
        </template>
      </el-table-column>

      <el-table-column prop="des" label="备注" width="200">
        <template slot-scope="{ row }">
          <span>{{ row.des || '--' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间" width="180">
      </el-table-column>
      <el-table-column label="操作" width="220">
        <template slot-scope="{ row }">
          <el-button-group>
            <el-button type="primary" size="mini" @click="handleEdit(row)"
              >编辑</el-button
            >
            <el-button type="danger" size="mini" @click="handleDelete(row)"
              >删除</el-button
            >
            <el-button type="primary" size="mini" @click="handleContent(row)"
              >内容管理</el-button
            >
          </el-button-group>
        </template>
      </el-table-column>
      <div slot="empty" class="emptyBg">
        <el-empty :image-size="200"></el-empty>
      </div>
    </el-table>
  </div>
</template>
<script>
import { sysNewsContentsQuery } from '@/api/admin/collect/sysNewsContents'
export default {
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
        pid: 0,
        classType: 3, //1.试卷 2.考试 3.栏目
      },
      tableData: [],
    }
  },
  mounted() {
    this.getList()
    this.$bus.$on('refreshExamClassifyList', (v) => {
      if (v) {
        Object.assign(this.listQuery, v)
      }
      this.getList()
    })
  },
  beforeDestroy() {
    this.$bus.$off('refreshExamClassifyList')
  },
  methods: {
    async getList() {
      let res = await this.$store.dispatch('sysClassifyList', this.listQuery)
      this.tableData = res.data
    },
    handleEdit(row) {
      this.$bus.$emit('showDialogExamClassifyAdd', row)
    },
    handleDelete(row) {
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '删除',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.delete(row)
        })
        .catch(() => {})
    },
    async delete(row) {
      await this.$store.dispatch('sysClassifyDel', row)
      this.getList()
    },
    handleContent(row) {
      let query = {
        page: 1,
        limit: 10,
        classifyId: row.id,
      }
      sysNewsContentsQuery(query).then((res) => {
        // console.log(res)
      })
    },
  },
}
</script>